﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Cn.Edwon.Web.ExtControl {
    public class CheckBoxTemplate : ITemplate {
        private String _CtrlName;
        public CheckBoxTemplate(String ctrlName) {
            _CtrlName = ctrlName;
        }
        public void InstantiateIn(Control Container) {
            LiteralControl lit = new LiteralControl();
            lit.ID = "litCheck";
            lit.DataBinding += new EventHandler(this.OnDataBinding);
            Container.Controls.Add(lit);
        }
        public void OnDataBinding(object sender, EventArgs e) {
            LiteralControl lit = (LiteralControl)sender;
            GridViewRow row = (GridViewRow)lit.NamingContainer;
            GridView gv = (GridView)row.NamingContainer;
            StringBuilder html = new StringBuilder("<input type=\"checkbox\" name=\"" + _CtrlName + "\"");
            html.Append(" value=\"" + gv.DataKeys[row.RowIndex].Value + "\" />");
            lit.Text = html.ToString();
        }
    }
}
